<script>
    $(function() {
        $("#desde").datepicker({dateFormat: 'dd/mm/yy', changeMonth: true, changeYear: true});
        $( "#hasta" ).datepicker({dateFormat: 'dd/mm/yy', changeMonth: true, changeYear: true});
    });
</script> 


<div class="row-fluid">
    <?php echo $this->render('/listados/menu.phtml'); ?>


    <div class="well well-small">
        <form name="form_busqueda" class="form-inline noPrint" method="POST" action="<?php echo $this->baseUrl(); ?>/admin/listados/dineroacobrar">
            <legend>Dinero a Cobrar</legend>
            <label class="control-label">Desde</label>
            <input id="desde" name="desde" value="<?php echo !empty($this->desde) ? $this->desde : "" ?>" class="input-small" type="text" />
            <label class="control-label">Hasta</label>
            <input id="hasta" name="hasta" value="<?php echo !empty($this->hasta) ? $this->hasta : "" ?>" class="input-small" type="text" />
            
            <label>Sucursal</label>
            <select id="sucursal" name="sucursal">
                <option value="0">Todas</option>
                <?php foreach ($this->sucursales as $sucursal) { ?>
                <option <?php echo $this->sucursal == $sucursal->getId() ? "selected" : "" ?> value="<?php echo $sucursal->getId(); ?>">
                    <?php echo $sucursal->getDescripcion(); ?></option>
                <?php } ?>
            </select>
            &nbsp;&nbsp;&nbsp;
            <input class="btn" value="Buscar" type="submit" />
        </form>

        <div class="row-fluid ">
            
            <div class="btn-toolbar pull-right">
                <button id="exportar_excel" class="btn btn-success noPrint" type="button"><i class=" icon-download icon-white"></i>  Exportar a Excel</button>
            </div>
            
            <table class="table table-condensed tabla_reducida" style="font-size: 12px;">
                <thead>
                    <tr>
                        <th>Cantidad de Cuotas</th><th>Monto Total</th>
                    </tr>
                </thead>
                <tbody style="font-size: 24px;font-weight: bold;">
                    <tr>
                        <td><?php echo $this->cantidad_cuotas_total; ?></td>
                        <td><?php echo number_format($this->monto_total_a_cobrar, 2, ",", ".") . " $" ?></td>
                    </tr>
                </tbody>
            </table>

        </div>
    </div>

</div>

<div class="row-fluid">
    <div class="well well-small">
        <legend>Mes Por Mes</legend>
        
        <table class="tabla_reducida" style="font-size: 12px;">
            <thead>
                <tr>
                    <th>Mes</th><th></th>
                </tr>
            </thead>
            <tbody style="font-size: 24px;font-weight: bold;">
                <?php foreach ($this->cuotas_por_mes as $mes => $datos): ?>
                <tr>
                    <?php $mes = explode("/", $mes) ?>
                    <td><?php echo $this->common->descripcionMes(intval($mes[0])) . " de ". $mes[1]; ?></td>
                    <td style="padding:0;">
                        <table style="width:100%;padding:0;margin:0;">
                    <?php foreach ($datos as $suc => $datos_suc): ?>
                    
                        <tr>
                            <td><?php echo $suc ?></td>
                            <td><?php echo $datos_suc["cant"] ?></td>
                            <td><?php echo number_format($datos_suc["monto"], 2, ",", ".") . " $" ?></td>
                        </tr>
                    
                    <?php endforeach; ?>
                        </table>
                    <td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
        
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function() {
        
        $("#exportar_excel").click(function(){
            var desde = $("#desde").val().replace("/","-").replace("/","-");
            var hasta = $("#hasta").val().replace("/","-").replace("/","-");
            var sucursal = $("#sucursal option:selected").val();
            
            var url = "<?php echo $this->baseUrl("/admin/listados/exportardineroacobrar"); ?>";
            url += "/desde/"+desde+"/hasta/"+hasta+"/sucursal/"+sucursal;
            $(location).attr("href", url);           
        });
        
    });
</script>



